package com.permissionmanager.service.impl;

import com.permissionmanager.entity.Page;
import com.permissionmanager.entity.Perm;
import com.permissionmanager.mapper.PermMapper;
import com.permissionmanager.service.PermService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * perm业务层
 *
 */
@Service
@RequiredArgsConstructor
public class PermServiceImpl implements PermService {

    private final PermMapper permMapper;

    @Override
    public List<Perm> findPerm(Integer id, String name,String pNo,Integer isOne) {
        return permMapper.findPerm(id,name,pNo,isOne,0);
    }



    /**
     * 新增
     * @param perm 权限信息（id、name、path、isOne）
     */
    @Override
    public void add(Perm perm) {
        permMapper.add(perm);
    }

    /**
     * 修改
     * @param perm （id）
     */
    @Override
    public void update(Perm perm) {
        permMapper.update(perm);
    }

    /**
     * 删除
     * @param id 参数
     */
    @Override
    public void del(Integer id) {
        permMapper.del(id);
    }

    /**
     * 分页查询
     */
    @Override
    public Page<Perm> findPage(Integer pageNum, Integer pageSize, String name) {
        Integer skipNum = (pageNum - 1) * pageSize;
        Page<Perm> page = new Page<>();
        List<Perm> list = permMapper.findPage(skipNum, pageSize, name);
        page.setTList(list);
        page.setTotal(list.size());
        return page;
    }

    @Override
    public List<Perm> findAll() {
        return permMapper.findAll();
    }
}
